package org.jeecg.modules.system.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.jeecg.modules.system.entity.SysDepart;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * 部门表 存储树结构数据的实体类
 */
@Data
@ApiModel(value="部门返回对象", description="部门信息树返回对象")
public class SysDepartTreeModel implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 对应SysDepart中的id字段,前端数据树中的key
     */
    @ApiModelProperty(value = "对应SysDepart中的id字段")
    private String key;

    /**
     * 对应SysDepart中的id字段,前端数据树中的value
     */
    @ApiModelProperty(value = "对应SysDepart中的id字段")
    private String value;

    /**
     * 对应depart_name字段,前端数据树中的title
     */

    @ApiModelProperty(value = "部门名称")
    private String title;


    private boolean isLeaf;
    // 以下所有字段均与SysDepart相同
    @ApiModelProperty(value = "对应SysDepart中的id字段")
    private String id;

    private String parentId;

    @ApiModelProperty(value = "部门名称")
    private String departName;

    private String departNameEn;

    private String departNameAbbr;

    private Integer departOrder;

    private String description;

    @ApiModelProperty(value = "机构类别 1=公司，2=组织机构，3=岗位")
    private String orgCategory;

    private String orgType;

    private String orgCode;

    private String mobile;

    private String fax;

    private String address;

    private String memo;

    private String status;

    private String delFlag;

    private String qywxIdentifier;

    private String createBy;

    private Date createTime;

    private String updateBy;

    private Date updateTime;

    //update-begin---author:wangshuai ---date:20200308  for：[JTC-119]在部门管理菜单下设置部门负责人，新增字段部门负责人ids
    /**
     * 部门负责人ids
     */
    @ApiModelProperty(value = "部门负责人ids")
    private String directorUserIds;
    //update-end---author:wangshuai ---date:20200308  for：[JTC-119]在部门管理菜单下设置部门负责人，新增字段部门负责人ids


    /**
     * 部门员额数
     */
    @ApiModelProperty(value = "部门员额数")
    private Integer member;
    /**
     * 正职数
     */
    @ApiModelProperty(value = "正职数")
    private Integer chiefPosition;
    /**
     * 副职数
     */
    @ApiModelProperty(value = "副职数")
    private Integer deputyPosition;

    /**
     * 正副职数合并后字段
     */
    @ApiModelProperty(value = "职数")
    private Integer position;

    @ApiModelProperty(value = "正职数-副职数")
    private String chiefPositionDeputyPositionStr;

    /**
     * 分、子公司
     */
    @ApiModelProperty(value = "分、子公司数")
    private Integer subsidiary;
    /**
     * 内设机构
     */
    @ApiModelProperty(value = "内设机构数")
    private Integer internalInstitutions;

    private List<SysDepartTreeModel> children = new ArrayList<>();

    /**
     * 将SysDepart对象转换成SysDepartTreeModel对象
     */
    public SysDepartTreeModel(SysDepart sysDepart) {
        this.key = sysDepart.getId();
        this.value = sysDepart.getId();
        this.title = sysDepart.getDepartName();
        this.id = sysDepart.getId();
        this.parentId = sysDepart.getParentId();
        this.departName = sysDepart.getDepartName();
        this.departNameEn = sysDepart.getDepartNameEn();
        this.departNameAbbr = sysDepart.getDepartNameAbbr();
        this.departOrder = sysDepart.getDepartOrder();
        this.description = sysDepart.getDescription();
        this.orgCategory = sysDepart.getOrgCategory();
        this.orgType = sysDepart.getOrgType();
        this.orgCode = sysDepart.getOrgCode();
        this.mobile = sysDepart.getMobile();
        this.fax = sysDepart.getFax();
        this.address = sysDepart.getAddress();
        this.memo = sysDepart.getMemo();
        this.status = sysDepart.getStatus();
        this.delFlag = sysDepart.getDelFlag();
        this.qywxIdentifier = sysDepart.getQywxIdentifier();
        this.createBy = sysDepart.getCreateBy();
        this.createTime = sysDepart.getCreateTime();
        this.updateBy = sysDepart.getUpdateBy();
        this.updateTime = sysDepart.getUpdateTime();
        this.directorUserIds = sysDepart.getDirectorUserIds();
        this.member = sysDepart.getMember();
        this.chiefPosition = sysDepart.getChiefPosition();
        this.deputyPosition = sysDepart.getDeputyPosition();
        this.subsidiary = sysDepart.getSubsidiary();
        this.internalInstitutions = sysDepart.getInternalInstitutions();
        String chiefPositionStr = Objects.isNull(sysDepart.getChiefPosition()) ? "0" : sysDepart.getChiefPosition() + "";
        String DeputyPositionStr = Objects.isNull(sysDepart.getDeputyPosition()) ? "0" : sysDepart.getDeputyPosition() + "";
        this.chiefPositionDeputyPositionStr = chiefPositionStr + "-" + DeputyPositionStr;
        this.position = sysDepart.getPosition();
//        if ("0-0".equals(chiefPositionDeputyPositionStr)){
//            this.chiefPositionDeputyPositionStr = "请选择职数";
//        }
        this.isLeaf = 0 != sysDepart.getIzLeaf();
    }

    public void setChildren(List<SysDepartTreeModel> children) {
        if (children == null) {
            this.isLeaf = true;
        }
        this.children = children;
    }

    public boolean getIsLeaf() {
        return isLeaf;
    }

    public void setIsLeaf(boolean isleaf) {
        this.isLeaf = isleaf;
    }

}
